// pages/search/search.ts
Page({
    data: {
        navHeight:0,
        menuButtonInfo: {
            bottom:0,
            height:0,
            top:0,
            left:0,
            right:0,
            width:0,
        },
        searchMarginTop: 0, // 搜索框上边距
        searchWidth: 0, // 搜索框宽度
        searchHeight: 0, // 搜索框高度
        search_history:[''],
        search_value:'',
        news:[],


      },
      back(){
        /* wx.navigateBack({
            delta: 1
          }) */
          wx.switchTab({
            url:`/pages/home/home`
        
        })
      },
      //搜索
      startSearch(e:any){
        console.log(e.target.dataset.value)
        if(e.target.dataset.value){
          this.setData({search_value:e.target.dataset.value})

        }else{
          console.log(this.data.search_value)
        }
        wx.navigateTo({
          url:`/pages/search_after/search_after?keyname=${this.data.search_value}`
      
      })
        //跳转搜索
      },
      //
      onLoad: function (option:{keyname:string}) {
        this.setData({search_value:option.keyname})
        var app = getApp();
        this.setData({
          news: app.globalData.history
        })
        this.setData({
            //获取胶囊一块的宽高
          menuButtonInfo: wx.getMenuButtonBoundingClientRect()
        })
        console.log(this.data.menuButtonInfo);
        //当前小程序运行在企业微信环境中,返回设备信息
        wx.getSystemInfo({
          success: (res) => {
            console.log(res)
            const { statusBarHeight } = res
            //结构状态栏的高度，单位px 减去上面的得边距
            console.log(statusBarHeight)
            const margin = this.data.menuButtonInfo.top - statusBarHeight
            console.log(margin)
            this.setData({
                //总上边距
              navHeight: (this.data.menuButtonInfo.height + statusBarHeight + (margin * 2)),
              searchMarginTop: statusBarHeight + margin, // 状态栏 + 胶囊按钮边距
              searchHeight: this.data.menuButtonInfo.height,  // 与胶囊按钮同高
              searchWidth: this.data.menuButtonInfo.right - this.data.menuButtonInfo.width, // 胶囊按钮右边坐标 - 胶囊按钮宽度 = 按钮左边可使用宽度
            //   main:214
            })
          },
        })
        this.setData({search_history:['华为P50','vivo X70','iphone13']})
      }
 
})